package com.ywd.materials.admin.controller;

import com.ywd.materials.admin.common.Common;
import com.ywd.materials.admin.common.CommonGoods;
import com.ywd.materials.admin.common.CommonGoodsType;
import com.ywd.materials.admin.dto.MaterialsGoodsDto;
import com.ywd.materials.admin.dto.query.MaterialsGoodsQuery;
import com.ywd.materials.admin.exception.R;
import com.ywd.materials.admin.exception.RPage;
import com.ywd.materials.admin.service.impl.MaterialsGoodsServiceImpl;
import com.ywd.materials.admin.service.impl.MaterialsGoodsTypeServiceImpl;
import com.ywd.materials.admin.vo.MaterialsGoodsVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.Schema;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author lk
 * @date 2024/4/17 13:53
 */
@AllArgsConstructor
@RestController
@RequestMapping("/goods")
@Tag(name = "物资管理")
public class MaterialsGoodsController {

    private final MaterialsGoodsServiceImpl materialsGoodsServiceImpl;
    private final MaterialsGoodsTypeServiceImpl materialsGoodsTypeServiceImpl;

    @PostMapping("/saveGoods")
    @Operation(summary = "新增物资")
    public R<Boolean> saveGoods(@Validated @RequestBody MaterialsGoodsDto dto) {
        return R.ok(materialsGoodsServiceImpl.saveGoods(dto));
    }

    @PutMapping("/updateGoods")
    @Operation(summary = "修改物资")
    public R<Boolean> updateGoods(@Validated @RequestBody MaterialsGoodsDto dto) {
        return R.ok(materialsGoodsServiceImpl.updateGoods(dto));
    }

    @DeleteMapping("/deleteGoods")
    @Operation(summary = "删除物资")
    public R<Boolean> deleteGoods(@Schema(description = "ID") @RequestParam Long id) {
        return R.ok(materialsGoodsServiceImpl.deleteGoods(id));
    }

    @PostMapping("/getGoodsPage")
    @Operation(summary = "查询物资列表(分页)")
    public R<RPage<List<MaterialsGoodsVo>>> getGoodsPage(@RequestBody MaterialsGoodsQuery query) {
        return R.ok(materialsGoodsServiceImpl.getGoodsPage(query));
    }

    @GetMapping("/getGoodsDetails")
    @Operation(summary = "查询物资详情")
    public R<MaterialsGoodsVo> getGoodsGoodsDetails(@Schema(description = "ID") @RequestParam Long id) {
        return R.ok(materialsGoodsServiceImpl.getGoodsDetails(id));
    }


    @GetMapping("/getGoodsPartList")
    @Operation(summary = "物资列表(筛选项)")
    public R<List<CommonGoods>> getGoodsPartList(@Schema(description = "名称") @RequestParam(required = false) String name) {
        return R.ok(materialsGoodsServiceImpl.getGoodsPartList(name));
    }


    @GetMapping("/getGoodsTypePartOneList")
    @Operation(summary = "物资类型列表(筛选项)(树形)")
    public R<List<CommonGoodsType>> getGoodsTypePartOneList() {
        return R.ok(materialsGoodsTypeServiceImpl.getGoodsTypePartOneList());
    }

}
